import Vue from 'vue'
import VueI18n from 'vue-i18n'

// ant  language resources
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import enUS from 'ant-design-vue/lib/locale-provider/en_US'

// custom language resources
import app_zh_CN from './lang/zh-CN'
import app_en_US from './lang/en-US'

Vue.use(VueI18n)

// 自动根据浏览器系统语言设置语言
const navLang = navigator.language
const localLang = (navLang === 'zh-CN' || navLang === 'en-US') ? navLang : false
const lang = window.localStorage.lang || localLang || 'zh-CN'

Vue.config.lang = lang

// vue-i18n 6.x+写法
// Vue.locale = () => {}
const messages = {
    'zh-CN': Object.assign(zhCN, app_zh_CN),
    'en-US': Object.assign(enUS, app_en_US)
}

const i18n = new VueI18n({
    locale: lang,
    messages: messages
})

const zh_CN = zhCN
const en_US = enUS

export { zh_CN, en_US }

export default i18n
